
using Domain;
using ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using WriteAPI.Command.Material;

namespace WriteAPI.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class MaterialReplenishmentController : ControllerBase
    {
        private readonly IMediator _mediator;

        public MaterialReplenishmentController(IMediator mediator)
        {
            _mediator = mediator;
        }

        ///// <summary>
        ///// 物料添加
        ///// </summary>
        ///// <param name="command"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public async Task<IActionResult> CreateWithDetails([FromBody] CreateMaterialReplenishmentWithDetailsCommand command)
        //{
        //    var result = await _mediator.Send(command);
        //    return Ok(result);
        //}
        /// <summary>
        /// 物料查询
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIPaging<MaterialReplenishment>> GetWithDetails([FromQuery] GetMaterialReplenishmentWithDetailsCommand request, CancellationToken cancellationToken)
        {
            return await _mediator.Send(request);



        }
        /// <summary>
        /// 物料明细查询
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<MaterialReplenishment> Getdan([FromQuery] GetMaterialDetailCommand request, CancellationToken cancellationToken)
        {

            return await _mediator.Send(request);
        }

        /// <summary>
        /// 物料主键删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<object>> DelWithDetails(DelMaterialReplenishmentWithDetailsCommand request,
   CancellationToken cancellationToken)
        {

            return await _mediator.Send(request);
        }
        /// <summary>
        /// 物料主键修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<object>> UpdateMaterial(UpdateMaterialReplenishmentWithDetailsCommand request, CancellationToken cancellationToken)
        {

            return await _mediator.Send(request);
        }

        [HttpGet]
        public async Task<APIPaging<MaterialReplenishment>> Getquan([FromQuery] GetMaterialCommand request, CancellationToken cancellationToken)
        {
            return await _mediator.Send(request);

        }
    }
}
